package phone.qyg.com.qyg.utils;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.app.application.QXApplication;
import com.app.utils.CommonUtil;

import phone.qyg.com.qyg.R;


/**
 * 作者：lblbh on 2017/6/5 14:00
 * 邮箱：lanbuhan@163.com
 * 功能：搜索 类型
 */
public class PopuUpdateApp {

    public static boolean isUpdate;
    public static PopupWindow popupWindow;
    public static PopupWindow setPopuAppUpdate( View v, String title, String msg ,final OnClickState onClickState){

        LayoutInflater inflater = (LayoutInflater) QXApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.popu_app_info, null);

        popupWindow = new PopupWindow(view,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        popupWindow.showAtLocation(v, Gravity.NO_GRAVITY, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT);
        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
		popupWindow.update();
        popupWindow.setBackgroundDrawable(new BitmapDrawable());



        TextView delete_content_text = (TextView) view.findViewById(R.id.delete_content_text);
        TextView delete_msg_text = (TextView) view.findViewById(R.id.delete_msg_text);
        delete_content_text.setText(CommonUtil.setAttributeText(title));
        delete_msg_text.setText(CommonUtil.setAttributeText(msg));

        view.findViewById(R.id.delete_quit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(isUpdate)return;
                if(popupWindow != null && popupWindow.isShowing()){
                    popupWindow.dismiss();
                }
                if(onClickState != null)
                    onClickState.OnItemClick(null,false);
            }
        });
        final TextView delete_sure = (TextView) view.findViewById(R.id.delete_sure);
        delete_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onClickState != null){
                    delete_sure.setEnabled(false);
                    onClickState.OnItemClick(delete_sure,true);
                }

                isUpdate = true;

            }
        });

        return popupWindow;
    }


    public interface OnClickState{
        public void OnItemClick(TextView view, boolean isState);
    }
}
